<?php

declare(strict_types=1);

namespace App\Controller;

use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Annotation\AutoController;
use App\Controller\BaseController;
use App\Model\Order;

#[AutoController]
class OrderController extends BaseController
{
    //订单列表
    public function orderList(RequestInterface $request)
    {
        $userId = $request->input('userId');
        if (empty($userId)) {
            $data['err'] = 1;
            $data['msg'] = '参数错误，重新登录';
        }

        $isAuth = $this->Auth($request, 0);
        $AuthInfo = json_decode($isAuth, true);
        if ($AuthInfo['err'] === 0) {
            $orderList = Order::query()->where('user_id', $userId)->with('orderGoods')->get();
            $data['err'] = 0;
            $data['msg'] = '获取成功';
            $data['orderList'] = $orderList;
        } else {
            $data['err'] = 1;
            $data['msg'] = '认证失败，重新登录';
        }
        return json_encode($data);
    }
}
